package com.yonyou.isv.demo.openapi.base.datacenter.impl;

import com.yonyou.isv.demo.openapi.base.datacenter.pojo.GatewayAddressResponse;
import org.springframework.http.ResponseEntity;

import java.util.Objects;


/**
 * @author nishch
 * @description: TODO
 * @date 2022/3/8
 */
public class QueryDataCenterUrlProviderImpl extends DataCenterUrlProviderImpl{

    /**
     * TODO：不建议每次都调用接口，租户一旦创建所属数据中心不会再改变，建议将租户地址对应关系持久化到数据库和缓存中
     * @return GatewayAddressResponse.GatewayAddressDTO
     */
    @Override
    public GatewayAddressResponse.GatewayAddressDTO queryGatewayAddress() {
        ResponseEntity<GatewayAddressResponse> responseEntity =  restTemplate.getForEntity(properties.getGatewayAddressUrl().replace("%s",queryTenantId()),GatewayAddressResponse.class);
        return Objects.requireNonNull(responseEntity.getBody()).getData();
    }

    /**
     * TODO：如果是ISV模式，需要在此处重写获取TenantId方法，一般伙伴需要将租户id存储入库
     * @return String
     */
    @Override
    public String queryTenantId() {
        return super.queryTenantId();
    }
}
